import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DoctorPage,
  FollowType,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PartialConsult,
  TopDep
} from '@/types/consult'
import { request } from '@/utils/request'
// 查询文章

export const getKnowledgePage = (data: KnowledgeParams) =>
  request<KnowledgePage>('patient/home/knowledge', 'GET', data)
// 获取医生列表
export const getDoctorPage = (data: PageParams) =>
  request<DoctorPage>('home/page/doc', 'GET', data)

// 关注操作
export const followOrUnfollow = (data: { type: FollowType; id: string }) =>
  request('like', 'post', data)

// 获取科室接口
export const getAllDep = () => request<TopDep[]>('dep/all')

// 上传接口
export const uploadImage = (file: File) => {
  const fm = new FormData()
  fm.append('file', file)
  return request<{ id: string; url: string }>('upload', 'post', fm)
}

// 获取预支付信息
export const getConsultOrderPre = (data: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('patient/consult/order/pre', 'GET', data)

// 问诊订单生成
export const getOrderId = (data: PartialConsult) =>
  request<{ id: string }>('patient/consult/order', 'post', data)

// 支付接口
export const getConsultOrderPayUrl = (data: {
  orderId: string
  paymentMethod: 0 | 1 | undefined
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'post', data)

// 获取订单详情
export const getConsultOrderDetail = (data: { orderId: string }) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'GET', data)

// 获取未读消息列表
export const unReadMsgList = () => request<number>('patient/message/unRead/all')

// 获取处方图片
export const getPerInfo = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`)

// 评价医生
export const EvaluteDoc = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 1 | 0
}) => request('patient/order/evaluate', 'POST', data)

// 问诊记录
export const getConsultOrderList = (data: ConsultOrderListParams) =>
  request<ConsultOrderPage>('patient/consult/order/list', 'GET', data)
// 取消订单
export const cancelOrder = (id: string) =>
  request(`patient/order/cancel/${id}`, 'put')
// 删除订单
export const delOrder = (id: string) => request(`patient/order/${id}`, 'delete')
